﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DAL;
using HomeStayWebCP.Models;

namespace HomeStayWebCP.Controllers
{
    public class RegionsController : Controller
    {
        //
        // GET: /Regions/

        public ActionResult Index()
        {
            return View();
        }
       public ActionResult GetDistrict(int province)
        {
            RegionModel model = new RegionModel();
            List<Region> listdistrict = model.SelectDistrict(province);
            List<SelectListItem> listitem2 = new List<SelectListItem>();
            if (listdistrict.Count > 0)
            {
                listitem2.Add(new SelectListItem
                {
                    Text = "All District",
                    Value = "-1"
                });
                foreach (var dis in listdistrict)
                {

                    listitem2.Add(new SelectListItem
                                      {
                                          Text = dis.Name,
                                          Value = dis.RegionID.ToString()
                                      });
                }
                
            }
            else
            {
                listitem2.Add(new SelectListItem
                {
                    Text = "Select District",
                    Value = "-1"
                });
                
            }
            ViewBag.District = listitem2;
            ViewBag.ProvinceMap = province;
            return PartialView("GetDistrict");

        }
       public ActionResult GetDistrictProvince(int province, int district)
       {
           RegionModel model = new RegionModel();
           List<Region> listdistrict = model.SelectDistrict(province);
           List<SelectListItem> listitem2 = new List<SelectListItem>();
           if (listdistrict.Count > 0)
           {
               listitem2.Add(new SelectListItem
               {
                   Text = "All District",
                   Value = "-1"
               });
               foreach (var dis in listdistrict)
               {

                   listitem2.Add(new SelectListItem
                   {
                       Text = dis.Name,
                       Value = dis.RegionID.ToString()
                   });
               }

           }
           else
           {
               listitem2.Add(new SelectListItem
               {
                   Text = "Select District",
                   Value = "-1"
               });

           }
           ViewBag.DistrictSearch = district;
           ViewBag.District = listitem2;
           ViewBag.ProvinceMap = province;
           return PartialView("GetDistrict");

       }
       
    }
}
